import 'package:flutter/material.dart';
import 'package:flutter_shop/pages/base/base_state.dart';
import 'package:flutter_shop/pages/common/login/provider/login_provider.dart';
import 'package:flutter_shop/pages/member/member_tab_page/member_tab_contract.dart';
import 'package:flutter_shop/pages/member/member_tab_page/member_tab_presenter.dart';
import 'package:flutter_shop/pages/member/member_tab_page/widget/my_order.dart';
import 'package:flutter_shop/pages/member/member_tab_page/widget/other_item.dart';
import 'package:flutter_shop/pages/member/member_tab_page/widget/test_third.dart';
import 'package:flutter_shop/pages/member/member_tab_page/widget/top_header.dart';
import 'package:flutter_shop/res/colors.dart';
import 'package:flutter_shop/res/styles.dart';
import 'package:provider/provider.dart';

///会员中心tab
class MemberTabPage extends StatefulWidget {
  @override
  _MemberTabPageState createState() => _MemberTabPageState();
}

class _MemberTabPageState extends BaseState<MemberTabPage, MemberTabPresenter> with AutomaticKeepAliveClientMixin implements MemberTabView {
  @override
  bool get wantKeepAlive => true;

  @override
  MemberTabPresenter createPresenter() => MemberTabPresenter();

  @override
  Widget build(BuildContext context) {
    super.build(context);

    LoginProvider provider = Provider.of<LoginProvider>(context);

    return Scaffold(
      body: SingleChildScrollView(
        child: Container(
          child: Column(
            children: <Widget>[
              TopHeader(),
              Gaps.v_gap_10,
              MyOrder(),
              Gaps.v_gap_10,
              OtherItem(),
              Gaps.v_gap_10,
              TestThird(),
              Gaps.v_gap_30,
              provider.isLogin ? _exitLogin() : Gaps.empty,
              Gaps.v_gap_30,
            ],
          ),
        ),
      ),
    );
  }

  Widget _exitLogin() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 30),
      child: MaterialButton(
        minWidth: double.infinity,
        height: 45,
        color: CommonColors.red,
        onPressed: () {
          mPresenter.exitLogin();
        },
        child: Text(
          '退出登录',
          style: TextStyle(color: Colors.white),
        ),
      ),
    );
  }
}
